<template>
  <div>
    <div v-if="!this.$store.loginFlag">
      <router-view></router-view>
    </div>
    <div v-if="this.$store.loginFlag">
      <Layout :siderFixed="true" :siderCollapsed="siderCollapsed">
        <Sider theme="white" style="box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 0px 1px;">
          <Row type="flex" justify="center" style="height:64px;align-items:center;">
            <!-- <img :src="logo" alt="Logo" style="height:40px; margin-right:8px;" /> -->
            <h3 v-show="!siderCollapsed">AI工具平台</h3>
          </Row>
          <Row>
            <Cell style="background-color: rgb(222, 222, 225);height: 1px;">&nbsp;</Cell>
          </Row>
          <paas-menu theme="h-menu-white"
            url="/system/sysmenus/home?sysCode=ollama&deviceCode=ollama-ai-mg"></paas-menu>
        </Sider>
        <Layout :headerFixed="true">
          <paas-header></paas-header>
          <Content class="shadow-box" style="margin: 10px;">
            <router-view></router-view>
            <!--          <div class="footer-text">
              司锐：15308066831
            </div> -->
          </Content>
        </Layout>
      </Layout>
    </div>
  </div>
</template>

<style scoped>
.shadow-box {
  background-color: white;
}

.footer-text {
  margin-top: 10px;
  color: rgba(199, 196, 196, 0.255);
  text-align: right;
  padding-bottom: 10px;
  bottom: 0;
  width: calc(100% - 20px);
}
</style>
<script>
import logo from "@/assets/images/logo.png";

export default {
  created() {
    window.addEventListener('resize', this.handleResize);
  },
  computed: {
    siderCollapsed() {
      return this.$store.menus.siderCollapsed;
    },
    selected() {
      return this.$store.apps.selected;
    },
    iframeUrl() {
      return this.$store.apps.iframeUrl;
    },
  },
  mounted() {
    if (this.$store.loginFlag) {
      if (this.$store.dicts.length == 0) {
        this.$post("/system/sysdict/getall", {}).then(res => {
          this.$store.dicts = res.data.data;
        });
      }
    } else {
      const queryString = window.location.search;
      const urlParams = new URLSearchParams(queryString);
      const token = urlParams.get('token');
      if (!!token) {
        let jsonObject = JSON.parse(token);
        this.$store.setLoginFlag(true);
        this.$store.setLoginInfo({
          loginId: jsonObject.loginId,
          loginName: jsonObject.loginName,
          token: jsonObject.token,
        });
        const expires = jsonObject.expires || 30;
        const inMinutes = new Date(new Date().getTime() + expires * 60 * 1000);
        document.cookie = "Authentication=" + jsonObject.token + "; expires=" + inMinutes.toUTCString() + "; path=/";
        location.href = "/";
      }
    }

  },
  data() {
    return {
      logo: logo,
    };
  },
  methods: {

  },
};
</script>